package com.zrk.core;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;

/**
 * 如果读写方法符合以下这种命名格式的类成为JavaBean
 * // 读方法:
 * public Type getXyz()
 * boolean字段比较特殊，它的读方法一般命名为isXyz()
 * // 写方法:
 * public void setXyz(Type value)
 */
public class JavaBeanLearn {

    /**
     * 使用Introspector类的getBeanInfo可以获取到这个类的所有信息
     * @param args
     * @throws IntrospectionException
     */
    public static void main(String[] args) throws IntrospectionException {
        BeanInfo beanInfo = Introspector.getBeanInfo(Person.class);
        for (PropertyDescriptor pd : beanInfo.getPropertyDescriptors()) {
            System.out.println(pd.getName());
            System.out.println("  " + pd.getWriteMethod());
            System.out.println("  " + pd.getReadMethod());
        }
    }
}

class Person {
    private String name;
    private int age;

    public String getName() { return this.name; }
    public void setName(String name) { this.name = name; }

    public int getAge() { return this.age; }
    public void setAge(int age) { this.age = age; }
}